﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Lor;

namespace ExpenseSystem.Fether
{
    public class FiscalPeriodFetcher : NormalFetcher<FiscalPeriodModel>
    {
        public FiscalPeriodModel GetDefault(long site,out string message)
        {
            IList<FiscalPeriodModel> result = List(site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows);
            if (result.Count > 0)
                return result.First();
            return null;
        }
        public bool DateInPeriod(long site,string date)
        {
            string message;
            FiscalPeriodModel fiscalPeriodModel = GetDefault(site,out message);
            DateTime dt1, dt2, dt3;
            DateTime.TryParse(date, out dt1);
            DateTime.TryParse(fiscalPeriodModel.OpenDate, out dt2);
            DateTime.TryParse(fiscalPeriodModel.DueDate, out dt3);
            return !(dt2 <= dt1 && dt3 >= dt1) ;
        }
        public bool DateInPeriod(long site, DateTime date)
        {
            string message;
            FiscalPeriodModel fiscalPeriodModel = GetDefault(site, out message);
            DateTime  dt2, dt3;
            DateTime.TryParse(fiscalPeriodModel.OpenDate, out dt2);
            DateTime.TryParse(fiscalPeriodModel.DueDate, out dt3);
            return !(dt2 > date || dt3 < date);
        }
    }
}